﻿#region using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ibba.src.norisk.DataAccess;
using ibba.src.norisk.BusinessEntities;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Diagnostics;
using System.Threading;

#endregion

/*****************************************************************************************************************          
 Copyright © 2010 - Banco Itaú BBA S.A          
          
 NaurezaBL : Faz acesso a classe TetoMitigacaoBl
            
 Histórico de Alterações:      
 29/07/2010 - Leandra M. Madureira	- Criacao OS393398
 26/10/2010 - Aline Abreu Alves (AAALVES)	- Criacao OS423540 

 *****************************************************************************************************************/

namespace ibba.src.norisk.BusinessLogic
{
    public class TetoMitigacaoBL
    {
        private TetoMitigacaoDb _tetomitigacaoDb;

        public TetoMitigacaoBL()
        {
            _tetomitigacaoDb = new TetoMitigacaoDb();
        }

        public List<BusinessEntities.TetoMitigacao> ObterTetoMitigacao(int codInstrumento, int? codBem, int? codNatureza)
        {
            return (_tetomitigacaoDb.ObterTetoMitigacao(codInstrumento, codBem, codNatureza));
        }

        public int AtualizarTetoMitigacao(List<BusinessEntities.TetoMitigacao> pTetoMitigacao, string pCodUsuario)
        {
            //Tranforma a lista em xml
            XmlNodeList nodes = null;
            string sXml = "";
            XmlDocument doc = new XmlDocument();

            XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(pTetoMitigacao.GetType());
            MemoryStream stream = new System.IO.MemoryStream();

            serializer.Serialize(stream, pTetoMitigacao);
            stream.Position = 0;
            doc.Load(stream);

            nodes = doc.SelectNodes("//ArrayOfTetoMitigacao");

            foreach (XmlNode node in nodes)
            {
                sXml += node.InnerXml;
            }

            doc = new XmlDocument();

            doc.LoadXml("<?xml version='1.0' encoding='UTF-16'?><root>" + sXml + "</root>");

            return _tetomitigacaoDb.AtualizarTetoMitigacao(doc.InnerXml, pCodUsuario);
        }

        public int ExcluirTetoMitigacao(int CodInstrumento, int CodBem, int CodNatureza, string CodUsuario)
        {
            return _tetomitigacaoDb.ExcluirTetoMitigacao(CodInstrumento, CodBem, CodNatureza, CodUsuario);
        }

        public int InserirTetoMitigacao(int CodInstrumento, int CodBem, int CodNatureza, decimal PercTetoMitigacao, string CodUsuario)
        {
            return _tetomitigacaoDb.InserirTetoMitigacao(CodInstrumento, CodBem, CodNatureza, PercTetoMitigacao, CodUsuario);
        }

        public int VerificarTetoMitigacao(int CodInstrumento, int CodBem, int CodNatureza)
        {
            return _tetomitigacaoDb.VerificarTetoMitigacao(CodInstrumento, CodBem, CodNatureza);
        }

        //public List<BusinessEntities.TetoMitigacao> ListarTetoMitigacaoLog()
        public Retorno ListarTetoMitigacaoLog()
        {
            return _tetomitigacaoDb.ListarTetoMitigacaoLog();
        }
    }
}